package com.woniuxy.propertyjava.service.impl;

import com.woniuxy.propertyjava.dao.EquipmentDao;
import com.woniuxy.propertyjava.entity.Equipment;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.service.EquipmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : author
 * @create 2022/7/5 9:29
 */
@Service
public class EquipmentServiceImpl implements EquipmentService {

    @Resource(type = EquipmentDao.class)
    EquipmentDao equipmentDao;


    @Override
    public PageBean<Equipment> getEquipmentPageBean(Equipment equipment, int pageIndex, int pageSize) {
        PageBean<Equipment> pageBean = new PageBean<>();
        pageBean.setBeanList(equipmentDao.selectEquipmentsByEquipmentProperty(equipment, pageIndex, pageSize));
        pageBean.setPageSize(pageSize);
        pageBean.setPageIndex(pageIndex);
        pageBean.setTotalRecode(equipmentDao.count(equipment));
        return pageBean;
    }

    @Override
    public void insertEquipment(Equipment equipment) {
        equipmentDao.insert(equipment);
    }

    @Override
    public void updataEquipment(Equipment equipment) {
        equipmentDao.update(equipment);
    }

    @Override
    public void deleteEquipment(int equipmentId) {
        equipmentDao.deleteById(equipmentId);
    }
}
